<script>
	$(document).ready(function(){
		
		// 编辑原材料方法
		$("a[class^='css']").click(function(){
			var tagList = $("#dish_tag_list").val().split(",");
			var _exist = $.inArray($.trim($(this).html()),tagList);
			if (_exist >= 0) {
				return false;
			}
			else {
				if ($("#dish_tag_list").val() != "") {
					tagList.push($(this).html());
					$("#dish_tag_list").val(tagList.join(","));
				}
				else {
					$("#dish_tag_list").val($(this).html());
				}
			}
			return false;
		});
	});
</script>

<%= form_for(@dish, :html => { :multipart => true } ) do |f| %>
<% if @dish.errors.any? %>
<div id="error_explanation">
  <h2><%= pluralize(@dish.errors.count, "error") %> prohibited this dish from being saved:</h2>
  <ul>
    <% @dish.errors.full_messages.each do |msg| %>
    <li>
      <%= msg %>
    </li>
    <% end %>
  </ul>
</div>
<% end %>

<div class="field">
  <%= f.label :name %>
  <br />
  <%= f.text_field :name %>
</div>
<div class="field">
  <%= f.label :price %>
  <br />
  <%= f.text_field :price %>
</div>
<div class="field">
  <%= f.label '菜系' %>
  <%= collection_select(:dish, :dish_type_id, DishType.all, :id, :type_name, :prompt => true) %>
</div>
<div class="field">
  <%= f.label '原料' %>
  <%= f.text_field :tag_list %>
  (中间逗号隔开)
  <br/>
  <% tag_cloud(@tags, %w(css1 css2 css3 css4)) do |tag, css_class| %>
  <%= link_to tag.name, "#", :class => css_class %>
  <% end %>
</div>
<div class="field">
  <%= f.label '上传首页展示图片'%>
  <%= f.file_field :image %>
  <%= image_tag @dish.image.url(:medium) %>
</div>
<div class="actions">
  <%= f.submit %>
</div>
<% end %>
